#include <stdio.h>
#include <string.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "wifi_connecter.h"

static void WifiConnectTask(void)
{
    WifiDeviceConfig config = {0};
    strcpy_s(config.ssid, sizeof(config.ssid), "YOUR_SSID"); // 填写热点的 SSID（不超过 32 个字符）
    strcpy_s(config.preSharedKey, sizeof(config.preSharedKey), "PASSWORD"); // 填写热点密码（需大于等于 8 个字符）
    config.securityType = WIFI_SEC_TYPE_PSK;
    printf("Connecting wifi...\n");
    int netId = ConnectToHotspot(&config);
    printf("ConnectToHotspot: %d\n", netId);
}

static void WifiConnectDemo(void)
{
    osThreadAttr_t attr;
    attr.name = "WifiConnectTask";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 10240;
    attr.priority = osPriorityNormal;
    if (osThreadNew(WifiConnectTask, NULL, &attr) == NULL)
    {
        printf("Failed to create WifiConnectTask!\n");
    }
}

SYS_RUN(WifiConnectDemo);
